package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tencent.mmkv.MMKV;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.response.PropertyPaymentBean;
import com.ygxsk.carhome.utils.CommUtils;

import java.math.BigDecimal;
import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023/12/25  17:33
 * @Description:物业缴费详情适配器
 */
public class PropertyPaymentDetailAdapter extends BaseQuickAdapter<PropertyPaymentBean, BaseViewHolder> {

    public PropertyPaymentDetailAdapter(int layoutResId, @Nullable List<PropertyPaymentBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, PropertyPaymentBean propertyPaymentBean) {

        if (propertyPaymentBean != null) {

            String roomNumber = propertyPaymentBean.getHouseNo();//房间编号先空着
            String paymentName = propertyPaymentBean.getPaymentName();

            //判断整个布局是否隐藏或者显示的标志
            String paymentRemarks = propertyPaymentBean.getRemark();

            String paymentStartTime = propertyPaymentBean.getStartTime();
            String paymentEndTime = propertyPaymentBean.getEndTime();

            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(paymentStartTime);
            stringBuffer.append(getContext().getResources().getString(R.string.kongge0) + getContext().getResources().getString(R.string.time_zhi) + getContext().getResources().getString(R.string.kongge0));
            stringBuffer.append(paymentEndTime);
            String paymentDateInterval = stringBuffer.toString();


            BigDecimal paymentAmount = propertyPaymentBean.getPayAmount();//费用总额度

            BigDecimal paymentAmountformat;

            if (paymentAmount != null) {
                paymentAmountformat = CommUtils.formatComma2BigDecimal(paymentAmount);
            } else {
                paymentAmountformat = CommUtils.formatComma2BigDecimal(CommUtils.valueOf(0.00));
            }

            String amountFinal = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) + paymentAmountformat;

            //备注布局
            RelativeLayout relativeLayoutRemarks = (RelativeLayout) baseViewHolder.findView(R.id.relativelayoutremarks);
            //时间戳底部的横线
//            TextView textViewHelpTimestampView = (TextView) baseViewHolder.findView(R.id.textViewHelpTimestamp);
            //底部最后一条的帮助横线
            TextView textViewHelpiInPaymenttpBottom = (TextView) baseViewHolder.findView(R.id.textviewhelpinpaymenttpbottom);

            if (!TextUtils.isEmpty(paymentRemarks)) {

                CommUtils.setViewVisible(relativeLayoutRemarks);
//                CommUtils.setViewGone(textViewHelpTimestampView);

                //备注信息
                baseViewHolder.setText(R.id.textvieworderdet, TextUtils.isEmpty(paymentRemarks) ? "" : paymentRemarks);

            } else {

                CommUtils.setViewGone(relativeLayoutRemarks);
//                CommUtils.setViewVisible(textViewHelpTimestampView);

            }


            //房屋编号
            baseViewHolder.setText(R.id.textpayroomnuinlistdet, TextUtils.isEmpty(roomNumber) ? "" : roomNumber);//房间编号
            //费用名称
            baseViewHolder.setText(R.id.textViewpaymentnamedet, TextUtils.isEmpty(paymentName) ? "" : paymentName);
            //日期内容
            baseViewHolder.setText(R.id.textpaydatetimedet, TextUtils.isEmpty(paymentDateInterval) ? "" : paymentDateInterval);
            //支付金额
            baseViewHolder.setText(R.id.textpaytypedesdet, amountFinal.toString());

            //判断是不是最后一条，如果是最后一条帮助布局不显示
            int indexPostion = getItemPosition(propertyPaymentBean);
            if (indexPostion == getData().size() - 1) {
                CommUtils.setViewGone(textViewHelpiInPaymenttpBottom);
            } else {
                CommUtils.setViewVisible(textViewHelpiInPaymenttpBottom);
            }

        }

    }
}
